package com.delivery.www.dao.DaoImpl;

import com.delivery.www.dao.BaseDao;
import com.delivery.www.dao.ComplaintDao;
import com.delivery.www.po.Complaint;
import com.delivery.www.util.JdbcUtils;

import java.sql.Connection;
import java.util.List;

/**
 * @author 12970
 */
public class ComplaintDaoImpl implements ComplaintDao {
    @Override
    public int doComplaint(int userId, String content, int type) {
        Connection connection = JdbcUtils.getConnection();
        String sql = "insert into complaint (user_id,content,type) values(?,?,?)";
        int i = 0;
        if (connection != null) {
            i = BaseDao.executeUpdate(connection, sql, userId, content, type);
            JdbcUtils.closeResource(connection, null, null);
        }
        return i;
    }

    @Override
    public List<Complaint> getComplaint() {
        Connection connection = JdbcUtils.getConnection();
        String sql = "select complaint_id,user_id,content,type from complaint";
        List<Complaint> complaints = null;
        if (connection != null) {
            complaints = BaseDao.getList(connection, Complaint.class, sql);
            JdbcUtils.closeResource(connection, null, null);
        }
        return complaints;
    }

    @Override
    public int deleteComplaint(int complaintId) {
        Connection connection = JdbcUtils.getConnection();
        int i = 0;
        if (connection != null) {
            String sql = "delete from complaint where complaint_id = ?";
            i = BaseDao.executeUpdate(connection, sql, complaintId);
            JdbcUtils.closeResource(connection, null, null);
        }
        return i;
    }
}
